﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tanks.Contracts;
using Microsoft.Xna.Framework.Input;

namespace TanksGame
{
    class AnimatedSprite:Sprite
    { 
        protected int _currentFrame;
        public readonly int _numberOfFrames;
        protected int _timeCount;
        protected int _timeForFrame ;

        public AnimatedSprite(MapItemType mapItemType, Texture2D texture, int x, int y, int size, int numberOfFrames, int timeForFrame)
            : base(mapItemType, texture, x, y, size)
        {
            _numberOfFrames = numberOfFrames;
            _timeForFrame = timeForFrame;
        }

        protected int CalcCurrentFrame(GameTime gameTime)
        {
            _timeCount += gameTime.ElapsedGameTime.Milliseconds;
            return ((_timeCount / _timeForFrame) % _numberOfFrames);
        }

        public override void Update(GameTime gameTime, KeyboardState keyboardState )
        {
            _currentFrame = CalcCurrentFrame(gameTime);
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
           Rectangle r = new Rectangle(234 * _currentFrame, 0, 234, 234);
           spriteBatch.Draw(Texture,Rectangle, r, Color.White);
           
        }
    }
}
